from pygame.locals import Rect
from lib.ZClass import ZClass
from lib.ZLabel import ZLabel
from res.lang import ch
from res.fun import _create_rect
from res.glo import color , size

class ZButton(ZClass):
    def __init__(self , screen , pos):
        super(ZButton , self).__init__()
        self.screen = screen
        self._size = size['button']['default']
        self._pos = size['button']['padding']
        self.background = _create_rect(color['button']['background']['default'] , self._size)
        self.label = ZLabel(self.screen)
        self.label.text = ch['button']['start']
        self.label._pos = size['label']['padding']
        area_pos = pos[0] + self._pos[0] , pos[1] + self._pos[1]
        self.area = Rect(area_pos , self._size)

    def draw(self):
        self.screen.blit(self.background , self._pos)
        self.label.draw()

    def update(self , mouse_pos):
        if self.area.collidepoint(mouse_pos):
            self.label.color = color['button']['font']['onmouseover']
            self.background = _create_rect(color['button']['background']['onmouseover'] , self._size)
        else:
            self.label.color = color['button']['font']['default']
            self.background = _create_rect(color['button']['background']['default'] , self._size)

    def isclick(self , mouse_pos , mouse_pressed):
        if self.area.collidepoint(mouse_pos):
            return True